//
//  PublishOrderDetailViewController.m
//  Hui
//
//  Created by HawkingWang on 16/11/1.
//  Copyright © 2016年 Hui. All rights reserved.
//

#import "PublishOrderDetailViewController.h"

@interface PublishOrderDetailViewController ()

/**订单标题*/
@property (weak, nonatomic) IBOutlet UILabel *orderTitle;
/**取送地址*/
@property (weak, nonatomic) IBOutlet UILabel *takeAddress;
@property (weak, nonatomic) IBOutlet UILabel *deliveryAddress;
/**进行中*/
@property (weak, nonatomic) IBOutlet UIView *statusView;
@property (weak, nonatomic) IBOutlet UILabel *statusBeing;
/**已送达*/
@property (weak, nonatomic) IBOutlet UILabel *statusDone;

/**配送费*/
@property (weak, nonatomic) IBOutlet UILabel *money;
/**取消发布*/
@property (weak, nonatomic) IBOutlet UIButton *canclePublishBtn;
/**订单进度View*/
@property (weak, nonatomic) IBOutlet UIView *orderStatusView;


/**收货人*/
@property (weak, nonatomic) IBOutlet UILabel *consigneeName;
@property (weak, nonatomic) IBOutlet UILabel *consigneeTime;
@property (weak, nonatomic) IBOutlet UIButton *callConsignee;
/**骑手*/
@property (weak, nonatomic) IBOutlet UILabel *deliveryManName;
@property (weak, nonatomic) IBOutlet UIButton *callDeliveryMan;

/**骑手取货*/
@property (weak, nonatomic) IBOutlet UIView *toTakeLine;
@property (weak, nonatomic) IBOutlet UIView *toTakePoint;
@property (weak, nonatomic) IBOutlet UILabel *toTakeLabel;
/**已送达*/
@property (weak, nonatomic) IBOutlet UIView *finishLine;
@property (weak, nonatomic) IBOutlet UIView *finishPoint;
@property (weak, nonatomic) IBOutlet UILabel *finishLabel;
/**联系骑手*/
@property (weak, nonatomic) IBOutlet UIView *callDeliveryManView;

/**地图*/
@property (weak, nonatomic) IBOutlet UIView *mapView;

@end

@implementation PublishOrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _callConsignee.layer.borderWidth = 0.5;
    _callConsignee.layer.borderColor = APPCOLOR.CGColor;
    _callDeliveryMan.layer.borderWidth = 0.5;
    _callDeliveryMan.layer.borderColor = RGBCOLOR(253, 151, 52).CGColor;
    
    [self setNav];
    
    switch (self.state) {
        case 0:
            [self notGetOrderSetting];
            break;
        case 1:
            [self beingOrderSetting1];
            break;
        case 2:
            [self beingOrderSetting2];
            break;
        case 3:
            [self finishOrderSetting];
            break;
        default:
            break;
    }
   
}

- (void)setNav{
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 24)];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 2, 12, 20)];
    imageView.image = [UIImage imageNamed:@"top-back-w"];
    [leftView addSubview:imageView];
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 24)];
    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [leftView addSubview:leftBtn];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftView];
    self.navigationItem.leftBarButtonItem = leftItem;
}

#pragma mark === 未接单 取消发布 ===
- (void)notGetOrderSetting{
    _statusView.hidden = NO;
    _statusBeing.text = @"未接单";
    _statusDone.hidden = YES;
    
    _canclePublishBtn.hidden = NO;
    _orderStatusView.hidden = YES;
    
    _callDeliveryManView.hidden = YES;
}
- (IBAction)cancleOrder:(id)sender {
    [SVProgressHUD show];
    [SVProgressHUD showSuccessWithStatus:@"订单已取消"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
        [self.navigationController popViewControllerAnimated:YES];
    });
}

#pragma mark === 进行中 ===
//已接单 未取货
- (void)beingOrderSetting1{
    _statusView.hidden = NO;
    _statusBeing.text = @"进行中";
    _statusDone.hidden = YES;
    
    _canclePublishBtn.hidden = YES;
    _orderStatusView.hidden = NO;
    _toTakeLine.backgroundColor = RGBCOLOR(199, 210, 218);
    _toTakePoint.backgroundColor = RGBCOLOR(199, 210, 218);
    _toTakeLabel.textColor = RGBCOLOR(199, 210, 218);
    _finishLine.backgroundColor = RGBCOLOR(199, 210, 218);
    _finishPoint.backgroundColor = RGBCOLOR(199, 210, 218)
    ;
    _finishLabel.textColor = RGBCOLOR(199, 210, 218);
    
    _callDeliveryManView.hidden = NO;
}
//已取货 未送达
- (void)beingOrderSetting2{
    _statusView.hidden = NO;
    _statusBeing.text = @"进行中";
    _statusDone.hidden = YES;
    
    _canclePublishBtn.hidden = YES;
    _orderStatusView.hidden = NO;
    _toTakeLine.backgroundColor = RGBCOLOR(111, 152, 182);
    _toTakePoint.backgroundColor = RGBCOLOR(111, 152, 182);
    _toTakeLabel.textColor = RGBCOLOR(111, 152, 182);
    _finishLine.backgroundColor = RGBCOLOR(199, 210, 218);
    _finishPoint.backgroundColor = RGBCOLOR(199, 210, 218)
    ;
    _finishLabel.textColor = RGBCOLOR(199, 210, 218);
    
    _callDeliveryManView.hidden = NO;
}


#pragma mark === 已完成 ===
- (void)finishOrderSetting{
    _statusView.hidden = YES;
    _statusDone.hidden = NO;
    
    _canclePublishBtn.hidden = YES;
    _orderStatusView.hidden = NO;
    _toTakeLine.backgroundColor = RGBCOLOR(111, 152, 182);
    _toTakePoint.backgroundColor = RGBCOLOR(111, 152, 182);
    _toTakeLabel.textColor = RGBCOLOR(111, 152, 182);
    _finishLine.backgroundColor = RGBCOLOR(111, 152, 182);
    _finishPoint.backgroundColor = RGBCOLOR(111, 152, 182)
    ;
    _finishLabel.textColor = RGBCOLOR(111, 152, 182);
    
    _callDeliveryManView.hidden = NO;
}


- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
